package com.zdmoney.laocaibao.common.interceptor;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.Set;

/**
 * Created by rui on 16/4/28.
 */
public class AccessInterceptor extends HandlerInterceptorAdapter implements ApplicationContextAware {

    private ThreadLocal<String> accessThreadLocal = new ThreadLocal<String>();


    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        String reqUrl = request.getRequestURI().replace(request.getContextPath(), "");
        String access_random = request.getParameter("access_random");
        accessThreadLocal.set(reqUrl + ",access_random=" + access_random);
        return true;
    }


    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

    }
}
